package com.xhq.webmvc.model;

/**
 *  返回json数据时的对象
 */
public class JsonModel {
    public static final int CODE_FAIL = 0;    //失败（未知原因）
    public static final int CODE_SUCCESS = 1; //成功
    public static final int CODE_404 = 404;   //资源未找到
    public static final int CODE_500 = 500;   //服务器错误



    private int code;  //是否成功
    private String message;  //返回消息
    private Object data;

    public JsonModel(int code, String message) {
        this(code, message, null);
    }

    public JsonModel(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static JsonModel success(String msg){
       return success(msg,null);
    }

    public static JsonModel success(String msg,Object data){
        return new JsonModel(CODE_SUCCESS,msg,data);
    }

    public static JsonModel fail(String msg){
        return fail(msg,null);
    }

    public static JsonModel fail(String msg,Object data){
        return new JsonModel(CODE_FAIL,msg,data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
